package com.atmilan.quartz.sync.pull.buyer.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atmilan.quartz.model.entity.buyer.BuyerBrand;
import com.atmilan.quartz.sync.pull.buyer.mapper.BuyerBrandMapper;
import com.atmilan.quartz.sync.pull.buyer.service.IBuyerBrandService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

@Service
public class BrandBrandServiceImpl extends ServiceImpl<BuyerBrandMapper, BuyerBrand> implements IBuyerBrandService {

    @Autowired
    BuyerBrandMapper buyerBrandMapper;

    @Override
    public BuyerBrand getBrandByBrandId(Integer brandId) {
        return this.getOne(Wrappers.<BuyerBrand>lambdaQuery()
                .eq(BuyerBrand::getBrandId,brandId), false);
    }

    @Override
    public List<String> getAllBrandId() {
        List<Object> list = buyerBrandMapper.selectObjs(new QueryWrapper<BuyerBrand>().select("brand_id"));
        return list == null? new ArrayList<String>():list.stream().map(o->o.toString()).collect(Collectors.toList());
    }

    @Override
    public List<String> getAllBrandName() {
        List<Object> list = buyerBrandMapper.selectObjs(new QueryWrapper<BuyerBrand>().select("brand_name"));
        return list == null? new ArrayList<String>():list.stream().map(o->o.toString()).collect(Collectors.toList());
    }

    @Override
    public BuyerBrand getBrandIdByBrandName(String brandName) {
        QueryWrapper<BuyerBrand> qw = new QueryWrapper<>();
        qw.lambda().eq(BuyerBrand::getBrandName,brandName);
        BuyerBrand buyerBrand = this.getOne(qw);
        return buyerBrand;
    }
}
